﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        @*<div class="form-group">
            <label class="col-sm-3 control-label ">ProductId<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="productId" col="ProductId" type="text" class="form-control" />
            </div>
        </div>*@
        <div class="form-group">
            <label class="col-sm-3 control-label ">产品<font class="red"> *</font></label>
            <div class="col-sm-8">
                <div id="productId" col="ProductId"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">数量</label>
            <div class="col-sm-8">
                <input id="number" col="Number" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">客户</label>
            <div class="col-sm-8">
                <input id="clientName" col="ClientName" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">地址</label>
            <div class="col-sm-8">
                <input id="adress" col="Adress" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">电话</label>
            <div class="col-sm-8">
                <input id="mobile" col="Mobile" type="text" class="form-control" />
            </div>
        </div>
        @*<div class="form-group">
            <label class="col-sm-3 control-label ">Status</label>
            <div class="col-sm-8">
                <input id="status" col="Status" type="text" class="form-control" />
            </div>
        </div>*@
        <div class="form-group">
            <label class="col-sm-3 control-label ">状态</label>
            <div class="col-sm-8" id="isValid" col="IsValid"></div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label ">说明</label>
            <div class="col-sm-8">
                <input id="remark" col="Remark" type="text" class="form-control" />
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {

        $("#isValid").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(StatusEnum).EnumToDictionaryString())) });

       
        $("#productId").ysComboBox({
            url: '@Url.Content("~/SaleManage/Product/GetListJson")',
            dataName: "Result",
            key: "Id",
            value: "ProductName",
            class: "form-control",
            multiple: false
        });

        getForm();

        $('#form').validate({
            rules: {
                productId: { required: true }
            }
        });
    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/SaleManage/Order/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        $('#form').setWebControls(obj.Result);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            ys.ajax({
                url: '@Url.Content("~/SaleManage/Order/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

